//
//  UIView+HSAddition.m
//  customer
//
//  Created by Holothurian on 2018/10/20.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "UIViewHSAddition.h"

@implementation UIView (HSAddition)

+ (id)newView:(CGRect)frame
{
    return [self newView:frame bgColor:[UIColor clearColor]];
}

+ (id)newView:(CGRect)frame bgColor:(UIColor *)bgColor
{
    id tView = [[[self class] alloc] initWithFrame:frame];
    [tView setBackgroundColor:bgColor];
    return tView;
}

#pragma mark - left
-(CGFloat)viewLeft{
    return self.frame.origin.x;
}

- (void)setViewLeft:(CGFloat)viewLeft{
    CGRect frame = self.frame;
    frame.origin.x = viewLeft;
    self.frame = frame;
}

#pragma mark - right
- (CGFloat)viewRight{
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setViewRight:(CGFloat)viewRight{
    CGRect frame = self.frame;
    frame.origin.x = viewRight - frame.size.width;
    self.frame = frame;
}

#pragma mark - top
- (CGFloat)viewTop{
    return self.frame.origin.y;
}

- (void)setViewTop:(CGFloat)viewTop{
    CGRect frame = self.frame;
    frame.origin.y = viewTop;
    self.frame = frame;
}

#pragma mark - bottom
- (CGFloat)viewBottom{
    return self.frame.origin.y + self.frame.size.height;
}

- (void)setViewBottom:(CGFloat)viewBottom{
    CGRect frame = self.frame;
    frame.origin.y = viewBottom - frame.size.height;
    self.frame = frame;
}

#pragma mark - width
- (CGFloat)viewWidth{
    return self.frame.size.width;
}

-(void)setViewWidth:(CGFloat)viewWidth{
    CGRect frame = self.frame;
    frame.size.width = viewWidth;
    self.frame = frame;
}

#pragma mark - height
- (CGFloat)viewHeight{
    return self.frame.size.height;
}

-(void)setViewHeight:(CGFloat)viewHeight{
    CGRect frame = self.frame;
    frame.size.height = viewHeight;
    self.frame = frame;
}

#pragma mark - centerX
- (CGFloat)viewCenterX{
    return self.center.x;
}

-(void)setViewCenterX:(CGFloat)viewCenterX{
    self.center = CGPointMake(viewCenterX, self.center.y);
}

#pragma mark - centerY
-(CGFloat)viewCenterY{
    return self.center.y;
}

-(void)setViewCenterY:(CGFloat)viewCenterY{
    self.center = CGPointMake(self.center.x, viewCenterY);
}

#pragma mark - allSubviews
-(NSArray*)allSubviews {
    NSMutableArray *arr = [NSMutableArray array];
    [arr addObject:self];
    for (UIView * subview in self.subviews) {
        [arr addObjectsFromArray:(NSArray*)[subview allSubviews]];
    }
    return arr;
}

@end
